﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PhotoList.Dal;

namespace PhotoList.Web.User
{
    public partial class ucChangePwd : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadUser();
            }
        }

        private void LoadUser()
        {
            string uID="";

            if (string.IsNullOrEmpty(Request.QueryString["uid"]))
            {
                uID = Page.Session["QT_UID"].ToString();
            }
            else
            {
                uID = Request.QueryString["uid"];
            }

            PhotoList.Dal.User uUser = new PhotoList.Dal.User(uID);
            this.tbUserID.Text = uUser.Uid;
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            PhotoList.Dal.User uUser = new PhotoList.Dal.User(this.tbUserID.Text);

            if (uUser.Pass != new QT.Basic.Tools().MD5(this.tbPassOld.Text.Trim()))
            {
                new QT.Basic.Tools().Alert("旧密码错误");
                return;
            }

            if (this.tbPassNew.Text != this.tbPassConfirm.Text)
            {
                new QT.Basic.Tools().Alert("两次输入新密码不一致");
                return;
            }

            uUser.Pass = new QT.Basic.Tools().MD5(this.tbPassNew.Text.Trim());

            if (uUser.ChangePwd())
            {
                new QT.Basic.Tools().Alert("密码修改成功");
            }
            else
            {
                new QT.Basic.Tools().Alert("操作失败");
                return;
            }

        }
    }
}